home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 5.3 KB | 163 lines | [TEXT/CCL2] |
- ;;; graphics-tools.lisp
- ;;;
- ;;; Paul McCartney, Spring 1992
- ;;;
- ;;; Copyright © 1992 Paul McCartney. All Rights Reserved.
- ;;;
- ;;; Washington University Medical Informatics Training Program
- ;;;
- ;;; DESCRIPTION:
- ;;;
- ;;;
- ;;; USE:
- ;;;
- ;;;
- ;;; HISTORY:
- ;;;
- ;;;
-
- (in-package :ccl)
-
- (require :quickdraw)
-
- (eval-when (:compile-toplevel :load-toplevel :execute)
- (export '(find-pixel-increment-h find-pixel-increment-v change-brightness
- point-value-in-range value-in-range draw-diamond
- draw-up-arrow draw-down-arrow)
- :ccl))
-
-
- (defun find-pixel-increment-h (scale inches power-of)
- (let* ((n (* inches (/ *pixels-per-inch-x* scale)))
- (power (ceiling (log n power-of))))
- (expt power-of power)))
-
-
- (defun find-pixel-increment-v (scale inches power-of)
- (let* ((n (* inches (/ *pixels-per-inch-y* scale)))
- (power (ceiling (log n power-of))))
- (expt power-of power)))
-
-
- (defun change-brightness (orig fraction)
- (make-color (round (color-red orig) fraction)
- (round (color-green orig) fraction)
- (round (color-blue orig) fraction)))
-
-
- (defun point-value-in-range (value)
- (min (max -32768 value) 32767))
-
-
- (defun value-in-range (min-value value max-value)
- (min (max min-value value) max-value))
-
-
- ;;; Return the height, in pixels, of a font. This is taken from the
- ;;; Macintosh Common Lisp 2.0 Reference, page 55.
- ;;;
- (defun line-height (font-spec)
- (multiple-value-bind (ascent descent widmax leading)
- (font-info font-spec)
- (declare (ignore widmax))
- (+ ascent descent leading)))
-
-
- (defun make-polygon-shape (view &rest points)
- (start-polygon view)
- (move-to view (first points))
- (dolist (point (rest points))
- (line-to view point))
- (get-polygon view))
-
-
- (defmethod draw-up-arrow ((view simple-view) topleft bottomright color &optional (outline-color color))
- (let* ((size (subtract-points bottomright topleft))
- (width (point-h size))
- (height (point-v size))
- (tip (add-points topleft (make-point (round width 2) 0)))
- (head-y (round (* height 0.45)))
- (left-point (add-points topleft (make-point 0 head-y)))
- (right-point (add-points topleft (make-point width head-y)))
- (left-center-point (add-points topleft (make-point (round (* width 2/5)) head-y)))
- (right-center-point (add-points topleft (make-point (round (* width 3/5)) head-y)))
- (left-bottom-point (add-points topleft (make-point (round (* width 2/5)) height)))
- (right-bottom-point (add-points topleft (make-point (round (* width 3/5)) height)))
- poly)
- (start-polygon view)
- (move-to view tip)
- (line-to view right-point)
- (line-to view right-center-point)
- (line-to view right-bottom-point)
- (line-to view left-bottom-point)
- (line-to view left-center-point)
- (line-to view left-point)
- (line-to view tip)
- (setf poly (get-polygon view))
- (with-focused-view view
- (with-fore-color color
- (paint-polygon view poly))
- (with-fore-color outline-color
- (frame-polygon view poly)) )
- (kill-polygon poly)
- ))
-
-
- (defmethod draw-down-arrow ((view simple-view) topleft bottomright color &optional (outline-color color))
- (let* ((size (subtract-points bottomright topleft))
- (width (point-h size))
- (height (point-v size))
- (tip (add-points topleft (make-point (round width 2) height)))
- (head-y (round (* height 0.55)))
- (left-point (add-points topleft (make-point 0 head-y)))
- (right-point (add-points topleft (make-point width head-y)))
- (left-center-point (add-points topleft (make-point (round (* width 2/5)) head-y)))
- (right-center-point (add-points topleft (make-point (round (* width 3/5)) head-y)))
- (left-bottom-point (add-points topleft (make-point (round (* width 2/5)) 0)))
- (right-bottom-point (add-points topleft (make-point (round (* width 3/5)) 0)))
- poly)
- (start-polygon view)
- (move-to view tip)
- (line-to view right-point)
- (line-to view right-center-point)
- (line-to view right-bottom-point)
- (line-to view left-bottom-point)
- (line-to view left-center-point)
- (line-to view left-point)
- (line-to view tip)
- (setf poly (get-polygon view))
- (with-focused-view view
- (with-fore-color color
- (paint-polygon view poly))
- (with-fore-color outline-color
- (frame-polygon view poly)) )
- (kill-polygon poly)
- ))
-
-
- (defmethod draw-diamond ((view simple-view) topleft bottomright color &optional (outline-color color))
- (let* ((size (subtract-points bottomright topleft))
- (width (point-h size))
- (height (point-v size))
- (top (add-points topleft (make-point (round width 2) 0)))
- (bottom (add-points topleft (make-point (round width 2) height)))
- (left (add-points topleft (make-point 0 (round height 2))))
- (right (add-points topleft (make-point width (round height 2))))
- poly)
- (start-polygon view)
- (move-to view top)
- (line-to view right)
- (line-to view bottom)
- (line-to view left)
- (line-to view top)
- (setf poly (get-polygon view))
- (with-focused-view view
- (with-fore-color color
- (paint-polygon view poly))
- (with-fore-color outline-color
- (frame-polygon view poly)) )
- (kill-polygon poly)
- ))
-
-
- (provide :graphics-tools)